package ptij.vocoder.baseModel.lp_analysis;

import ptolemy.actor.*;
import ptolemy.kernel.*;
import ptolemy.kernel.util.*;
import ptolemy.data.ObjectToken;
import ptolemy.data.type.*;

import ptij.vocoder.baseModel.*;

//////////////////////////////////////////////////////////////////////////
//// Int_lpc
/** Inclui a funcionalidade dos modulos Int_Lpc e No_speech_upd

@author Ivan Jeukens
@version v 0.1 07/08/2003
*/
public class Int_lpc extends TypedAtomicActor {

    public Int_lpc(CompositeEntity container, String name) throws
            IllegalActionException, NameDuplicationException {
        super(container, name);

        A_t = new TypedIOPort(this, "A_t", true, false);
        A_t.setTypeEquals(BaseType.OBJECT);

        lsp_mid_q = new TypedIOPort(this, "lsp_mid_q", true, false);
        lsp_mid_q.setTypeEquals(BaseType.OBJECT);

        lsp_new = new TypedIOPort(this, "lsp_new", true, false);
        lsp_new.setTypeEquals(BaseType.OBJECT);
        
        lsp_new_q = new TypedIOPort(this, "lsp_new_q", true, false);
        lsp_new_q.setTypeEquals(BaseType.OBJECT);

        txdtx_ctrl = new TypedIOPort(this, "txdtx_ctrl", true, false);
        txdtx_ctrl.setTypeEquals(BaseType.OBJECT);

        lsp_old = new TypedIOPort(this, "lsp_old", false, true);
        lsp_old.setTypeEquals(BaseType.OBJECT);

        Aq_t = new TypedIOPort(this, "Aq_t", false, true);
        Aq_t.setTypeEquals(BaseType.OBJECT);
    }

    ///////////////////////////////////////////////////////////////////
    ////                     ports and parameters                  ////

    // Input ports
    public TypedIOPort A_t;
    public TypedIOPort lsp_mid_q;
    public TypedIOPort lsp_new_q;
    public TypedIOPort lsp_new;
    public TypedIOPort txdtx_ctrl;
    
    // Output Ports
    public TypedIOPort Aq_t;
    public TypedIOPort lsp_old;

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void initialize() throws IllegalActionException {
        super.initialize();

    }

    public void fire() throws IllegalActionException {
        ObjectToken obj = (ObjectToken) txdtx_ctrl.get(0);
        Short txdtx = (Short) obj.getValue();

        if((txdtx.shortValue() & Cnst.TX_SP_FLAG) != 0) {
            obj = (ObjectToken) lsp_mid_q.get(0);
            Short [] arg2 = (Short []) obj.getValue();

            obj = (ObjectToken) lsp_new_q.get(0);
            Short [] arg3 = (Short []) obj.getValue();

            Short [] arg4 = new Short[Cnst.MP1*4];

            _int_lpc(_lsp_old_q, arg2, arg3, arg4);

            Short [] old = new Short[Cnst.M];
            Short [] old_q = new Short[Cnst.M];

            obj = (ObjectToken) lsp_new.get(0);
            Short [] lnew = (Short []) obj.getValue();

            for(int i = 0; i < Cnst.M; i++) {
                old[i] = new Short(lnew[i].shortValue());
                _lsp_old_q[i] = new Short(arg3[i].shortValue());
            }

            lsp_old.broadcast(new ObjectToken(old));
            Aq_t.broadcast(new ObjectToken(arg4));
        }
        else {
            obj = (ObjectToken) A_t.get(0);
            Short [] at = (Short []) obj.getValue();
            
            Short [] old = new Short[Cnst.M];
            Short [] old_q = new Short[Cnst.M];

            obj = (ObjectToken) lsp_new.get(0);
            Short [] lnew = (Short []) obj.getValue();

            for(int i = 0; i < Cnst.M; i++) {
                old[i] = new Short(lnew[i].shortValue());
                old_q[i] = new Short(lnew[i].shortValue());
            }


            lsp_old.broadcast(new ObjectToken(old));
            Aq_t.broadcast(new ObjectToken(at));
        }
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////

    private void _int_lpc(Short [] lsp_old, Short [] lsp_mid, 
            Short [] lsp_new, Short [] A) {
        
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private variables                 ////

    private Short [] _lsp_old_q;

}
